﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace VIP_Shop.Business_Logic
{
    class TimTheoLoai
    {
        DataTable datatable = new DataTable();
        VIP_Shop.Access_Data.AccessData data;
        Form frm;

        public TimTheoLoai(VIP_Shop.GUI.TimTheoLoai frm )
        {
            data = new Access_Data.AccessData();
            this.frm = frm;
        }
        public void show()
        {
          
            DataTable table = data.get_Datatable1("select * from loaihang");
            ComboBox cb = (ComboBox)frm.Controls["comboBox1"];
            cb.DataSource = table;
            cb.DisplayMember = "tenloai";
            cb.ValueMember = "maloai";
            cb.SelectedIndex = 1;
            cb.SelectedIndex = 0;

        }
        public void finded()
        {
            try
            {
                ComboBox cb = (ComboBox)frm.Controls["comboBox1"];
                string maloai = cb.SelectedValue.ToString();
                DataTable table = data.get_Datatable1("select * from mathang where maloai='" + maloai + "'");
                BindingSource binding1 = new BindingSource();
                binding1.DataSource = table;
                DataGridView grid1 = (DataGridView)frm.Controls["dataGridView1"];
                grid1.DataSource = binding1;
            }
            catch (SqlException err)
            {
                MessageBox.Show(err.Message);
            }
        }
        
    }
}
